import VueRouter from 'vue-router';
import Vue from 'vue';
Vue.use(VueRouter)

// 获取原型对象push函数
const VueRouterPush = VueRouter.prototype.push
// 修改原型对象中的push函数
VueRouter.prototype.push = function push(to) {
  return VueRouterPush.call(this, to).catch(err => err)
}


const router = new VueRouter({
  scrollBehavior: () => ({ y: 0 }),//路由跳转后页面置顶
  routes: [
    {
      path: '/',
      component: () => import('@/components/Login')
    },
    {
      path: '/main',
      component: () => import('@/pages/Main/index.vue'),
      children: [
        {
          path: '/search',
          component: () => import('@/pages/Search/index.vue')
        },
        {
          name: 'hotdishes',
          path: '/hotdishes',
          component: () => import('@/pages/HotDishes/index.vue')
        },
        {
          name: 'coldDishes',
          path: '/colddishes',
          component: () => import('@/pages/ColdDishes/index.vue')
        },
        {
          name: 'soup',
          path: '/soup',
          component: () => import('@/pages/Soup/index.vue')
        },
        {
          name: 'stapleFood',
          path: '/staplefood',
          component: () => import('@/pages/StapleFood/index.vue')
        },
        {
          path: '/personalInformation',
          component: () => import('@/pages/PersonalInformation/index.vue')
        },
        {
          path: '/menu',
          component: () => import('@/pages/Menu/index.vue')
        },
        {
          path: '/match',
          component: () => import('@/pages/Match/index.vue')
        },
        {
          path: '/dishManagement',
          component: () => import('@/pages/DishManagement/index.vue')
        },
        {
          path: '/userManagement',
          component: () => import('@/pages/UserManagement/index.vue')
        },
        {
          path: '/dishRecord',
          component: () => import('@/pages/DishRecord/index.vue')
        },
        {
          name: 'detail',
          path: '/detail',
          component: () => import('@/pages/Detail/index.vue')
        },
        {
          name: 'home',
          path: '/home',
          component: () => import('@/pages/Home/index.vue')
        },
        {
          name: 'role',
          path: '/role',
          component: ()=> import('@/pages/Role/index.vue')
        }
      ]
    },
    {
      path: '/register',
      component: () => import('@/pages/Register/index.vue')
    },
    {
      path: '/login',
      component: () => import('@/components/Login')
    },
  ]
})

export default router
